package com.lan.app.api;


import com.lan.app.repository.Tb;
import com.lan.app.service.ITbService;
import com.lan.support.page.Page;
import com.lan.support.page.PageHelper;
import com.lan.support.response.json.R;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("api/tb")
public class TbApi {

    @Resource
    private ITbService tbService;


    @ResponseBody
    @RequestMapping(value = "list")
    public R list(Tb tb, PageHelper helper) {
        Page<Tb> page = tbService.page(helper, tb);
        return R.OK(page);
    }


    @ResponseBody
    @RequestMapping(value = "all")
    public R all(boolean isTp) {
        List<Tb> list = tbService.getList(isTp);
        return R.OK(list);
    }

    @ResponseBody
    @RequestMapping(value = "add")
    public R add(Tb Tb) {
        Integer id = tbService.save(Tb);
        return R.OK(id);
    }


    @ResponseBody
    @RequestMapping(value = "del/{id}")
    public R del(@PathVariable Integer id) {
        tbService.del(id);
        return R.OK();
    }

    @ResponseBody
    @RequestMapping(value = "update")
    public R update(Tb tb) {
        tbService.updateById(tb);
        return R.OK();
    }

    @ResponseBody
    @RequestMapping(value = "detail/{id}")
    public R detail(@PathVariable Integer id) {
        Tb tb = tbService.get(id);
        return R.OK(tb);
    }
}
